package com.yizn.learn.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * 测试
 *
 * @author yisl
 * @create 2020-08-30 00:17
 */
public class CountDownLatchTest {

    private static CountDownLatch countDownLatch = new CountDownLatch(5);

    static class BossThread extends Thread{
        @Override
        public void run() {
            System.out.println("Bosss 在会议室等待，共"+ countDownLatch.getCount()+"参加会议");

            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("Boss 说人到齐开始开会");
        }
    }

    static class Boss1Thread extends Thread{
        @Override
        public void run() {
            System.out.println("Bosss1 在会议室等待，共"+ countDownLatch.getCount()+"参加会议");

            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("Boss1 说人到齐开始开会");
        }
    }

    static class EmployeeThread extends Thread{
        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "进入会议室");
            countDownLatch.countDown();
            System.out.println(Thread.currentThread().getName() + "坐下");
        }
    }

    public static void main(String[] args) {
        new BossThread().start();
        new Boss1Thread().start();
        for(int i=0; i<5; i++){
            new EmployeeThread().start();
        }
    }
}
